我一直都很想寫寫看屬於自己的音樂機器人,因此上網找了很多資料也按照資料安裝了一些模塊,但安裝模塊發生了很多問題,大部分都是import不進來但都顯示安裝好了
import discord
from discord.ext import commands
import youtube_dl
intents = discord.Intents.default()
intents.message_content = True
bot = commands.Bot(command_prefix='!', intents=intents)
@bot.command()
async def play(ctx, url):
  channel = ctx.author.voice.channel
  voice_client = await channel.connect()
  ydl_opts = {
    'format': 'bestaudio/best',
    'postprocessors': [{
      'key': 'FFmpegExtractAudio',
      'preferredcodec': 'mp3',
      'preferredquality': '192',  
    }],
  }
  with youtube_dl.YoutubeDL(ydl_opts) as ydl:
    info = ydl.extract_info(url, download=False) 
    url2 = info['formats'][0]['url']
  print(url2)
  #后续播放音频的代码
@play.error
async def error(ctx, error):
  print(error)
bot.run(‘token’)
上面這隻程式是我在網路上加GPT結合出來的簡易音樂機器人程式碼,但在執行這隻程式時一直報錯,網路上說是我沒安裝pynacl

但我執行 pip3 install pynacl也確定他pyancl有安裝了
我安裝了yt_dlp但他無法import進來
後來改成安裝youtube_dl並改成import yputube_dl他就正常了
明天會講其他import的問題~